package com.cenntro.nearr.controller;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cenntro.nearr.base.BaseController;
import com.cenntro.nearr.common.Result;
import com.cenntro.nearr.vo.LocationVO;
import com.google.common.collect.ImmutableMap;

import springfox.documentation.annotations.ApiIgnore;


@RestController
@RequestMapping("/location")
public class LocationController extends BaseController{

	
	private Logger LOG = LoggerFactory.getLogger(LocationController.class);
	
	@Autowired
	private com.cenntro.nearr.service.LocationService locationService;

//	@ApiOperation(value = "查找", notes = "根据ID查找")
//	@RequestMapping(value = "/selectById", method = RequestMethod.GET)
//	@ResponseBody
//	public Result selectById(Integer id) {
//		LOG.info("selectById id{}", id);
//		AddressVO addr = addressService.selectById(id);
//		return Result.ok(addr);
//	}
	
	/**
	 * 不分页
	 * @param addr
	 * @return
	 */
	
	@CrossOrigin
	@ApiIgnore
	@RequestMapping(value = "/select", method = RequestMethod.GET)
	@ResponseBody
	public Result select(LocationVO locationVO) {
		List<LocationVO> list = locationService.selectPage(locationVO);
		
		List<Map<String, Object>> volist = com.google.common.collect.Lists.newArrayList();
		for (LocationVO vo : list){
			Map<String, Object> map = ImmutableMap.of("locationId", vo.getLocationId(), "address", StringUtils.defaultIfBlank(vo.getAddress(), ""));
			volist.add(map);
		}
		return Result.ok(volist);
	}

	
}
